//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Cilindro.h"

//---------------------------------------------------------------------------
Cilindro::Cilindro(double radiobase,double radiocima, double altura, int nlados, int rodajas){
        _radiobase=radiobase;
        _radiocima=radiocima;
        _altura=altura;
        _nLados=nlados;
        _nParalelos=rodajas;

        _tieneLuz=false;

        _cutoff=60.0;
                          /*
        GLfloat v[4];
        v[0]=0.0;
        v[1]=-1.0;
        v[2]=0.0;
        v[3]=0.0;
        v[0]=0.0;
        v[1]=-1.0;
        v[2]=0.0;
        v[3]=0.0;     */


        GLfloat LuzDifusa[]={0.5,0.5,0.5,0.5};
        GLfloat LuzAmbiente[]={0.0,0.0,0.0,0.0};
        GLfloat LuzEspecular[]={1.0,1.0,1.0,1.0};
        glLightfv(GL_LIGHT1,GL_DIFFUSE,LuzDifusa);
        glLightfv(GL_LIGHT1,GL_AMBIENT,LuzAmbiente);
        glLightfv(GL_LIGHT1,GL_SPECULAR,LuzEspecular);

        glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, _cutoff);
        glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 0.0);
                                                 /*
        glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, v);
        v[1]=0.0;
        v[3]=1.0;

        glLightfv(GL_LIGHT1, GL_POSITION, v); */
}

Cilindro::~Cilindro(){
}

void Cilindro::dibuja(){
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
                glMultMatrixd(_marco->getMatriz());
                if(_tieneLuz){
                        GLfloat v[4];
                        v[0]=0.0;
                        v[1]=0.0;
                        v[2]=0.0;
                        v[3]=1.0;
                        glLightfv(GL_LIGHT1, GL_POSITION, v);
                        v[2]=1.0;
                        v[3]=0.0;
                        glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, v);
                        glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, _cutoff);
                }
                gluQuadricDrawStyle(_objeto,GLU_FILL);
                glColor4f(_color._r,_color._g,_color._b,1.0);
                gluCylinder(_objeto,_radiobase,_radiocima,_altura,_nLados,_nParalelos);
        glPopMatrix();
}
void Cilindro::escalaCO(double cutoff){
        if(cutoff>1){
                _cutoff-=5.0*cutoff;
        }else{
                _cutoff+=5.0*(1/cutoff);
        }
        glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, _cutoff);
}

//---------------------------------------------------------------------------

#pragma package(smart_init)
